import { PSEditorImpl } from '../pseditor-impl';
import { IPSArray } from './ipsarray';
import { IPSSysValueRule } from '../../valuerule/ipssys-value-rule';

export class PSArrayImpl extends PSEditorImpl implements IPSArray {
  get dataType(): string {
    return this.M.dataType || 'STRING';
  }

  get maxLength(): number {
    return this.M.maxLength;
  }

  get maxValue(): number {
    return this.M.maxValue;
  }

  get minLength(): number {
    return this.M.minLength != null ? this.M.minLength : 0;
  }

  get minValue(): number {
    return this.M.minValue;
  }

  protected pssysvaluerule: IPSSysValueRule | null = null;

  getPSSysValueRule(): IPSSysValueRule | null {
    if (this.pssysvaluerule != null) return this.pssysvaluerule;
    const value = this.M.getPSSysValueRule;
    if (value == null) {
      return null;
    }
    this.pssysvaluerule = this.getPSModel4('valuerule.IPSSysValueRule', value, 'getPSSysValueRule') as IPSSysValueRule;
    return this.pssysvaluerule;
  }

  get psSysValueRule(): IPSSysValueRule | null {
    return this.getPSSysValueRule();
  }

  getPSSysValueRuleMust(): IPSSysValueRule {
    const value = this.getPSSysValueRule();
    if (value == null) {
      throw new Error('未指定值规则');
    }
    return value;
  }

  get precision(): number {
    return this.M.precision;
  }

  get showMaxLength(): boolean {
    return this.M.showMaxLength != null ? this.M.showMaxLength : false;
  }

  get cls(): string {
    return 'PSArrayImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.editor.IPSArray' || cls == 'control.editor.IPSNumberEditor' || cls == 'control.editor.IPSTextEditor') return true;
    return super.instanceof(cls);
  }
}
